//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_STUBCONTEXT_H__
#define __ELASTOS_STUBCONTEXT_H__
#include <eladef.h>

#if (defined(_KDBAGENT) || defined(_UDBAGENT))

const UInt32 c_uTraceBit = 0x100;
const UInt32 c_uDbgInstructionLen = 1;

typedef enum RegIndex
{
    EAXINDEX = 0, ECXINDEX, EDXINDEX, EBXINDEX, ESPINDEX, EBPINDEX, ESIINDEX,
    EDIINDEX, EIPINDEX, EFLAGSINDEX, CSINDEX, SSINDEX, DSINDEX, ESINDEX,
    FSINDEX, GSINDEX
} RegIndexs;

struct StubContext
{
    UInt32 eax, ecx;
    UInt32 edx, ebx;
    UInt32 esp, ebp, esi, edi;
    UInt32 eip, eflags, cs;
    UInt32 ss, ds;
    UInt32 es, fs, gs;

    void  SetEip(UInt32 uEip) { eip = uEip; }
    void  DisableTrace() { eflags &= ~c_uTraceBit; }
    void  EnableTrace() { eflags |= c_uTraceBit; }

#if defined(_UDBAGENT)
    void SetupUdbContext(InterruptContext *pCxt, StubContext *pUdbCxt);
    void RestoreUdbInterruptContext(InterruptContext *pCxt, \
                                    StubContext *pUdbCxt);
#endif // #if defined(_UDBAGENT)

#if defined(_KDBAGENT)
    void SetupKdbContext(InterruptContext *pCxt, StubContext *pKdbCxt);
    void RestoreKdbInterruptContext(InterruptContext *pCxt, \
                                    StubContext *pKdbCxt);
#endif //#if defined(_KDBAGENT)
};

const size_t c_uRegBytes = sizeof(UInt32);
const size_t c_uRegAllBytes = sizeof(StubContext);

#if defined(_KDBAGENT)
void SwitchToKdbStack(UInt32 uKdbStack);
#endif //#if defined(_KDBAGENT)

//#if defined(_UDBAGENT)
// void SwitchToUdbStack(UInt32 uUdbStack);
//#endif //#if defined(_UDBAGENT)

#endif //#if (defined(_KDBAGENT) || defined(_UDBAGENT))

EXTERN void KdbHandler(vector_t vector, InterruptContext *pCxt);

EXTERN void UdbHandler(vector_t vector, InterruptContext *pCxt);

#endif // __ELASTOS_STUBCONTEXT_H__
